"use strict";

const BaseModel = require("../basics/mysql/mapper");
const Result = require("../basics/result");
class HomeModel extends BaseModel {
  constructor(cloud) {
    super(cloud, "user_info");
  }

  /**
   * 获取实例
   * @param {*} cloud 
   */
  static getInstant(cloud) {
    return new HomeModel(cloud);
  }


  /**
   * 查询当条
   * @param {*} openId 
   */
  async selectOneByOpenId(openId) {
    const ex = this.createExample();
    ex.criteria.andEqual("openId", openId);
    const data = await this.selectOneByExample(ex);
    if (!data) {
      throw Result.error(Result.constant.loginfail, "请先预约");
    } else {
      return data;
    }
  }

  /**
  * 去预约
  * @param {*} openId 
  */
  async goOrder(openId, mixNick, phone) {
    return await this.insertOne({ openId, mixNick, phone });
  }


  async deleteOrder() {
    console.log("=============================12")
    const sql = `delete from user_info`;
    const data = await this.mfSql(sql, []);
    console.log("data",data);
  }

}

module.exports = HomeModel;